<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>修改产品</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="description" content="修改产品">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/sm/pages/css/style.css">
<script type='text/javascript' src='/sm/dwr/interface/managerAjax.js'></script>
<script type='text/javascript' src='/sm/dwr/engine.js'></script>
<script type='text/javascript' src='/sm/pages/js/validator.js'></script>
  <script type='text/javascript'>

      
      function mod(){
          var form = document.getElementById("modForm");
          if(isNull(form.name.value)){
              alert("请输入产品名称！");
              return false;
          }
          if(isNull(form.no.value)){
              alert("请输入产品编号！");
              return false;
          }else{
             if(!isNumberOr_Letter(form.no.value)){
                 alert("产品编号只能为数字、字母及下划线！");
                 return false;
             }             
          }
          if(!isInteger(form.currentTotalNumber.value)){
              alert("当前产品总量只能为数字！");
              return false;
          }
          if(!isInteger(form.totalNumber.value)){
               alert("产品总量只能为数字！");
              return false;
          }
          managerAjax.checkNameAndNo(form.name.value,form.no.value,modCallBack);
      }
      
      function modCallBack(result){
          var form = document.getElementById("modForm");
          if(form.name.value != form.oldName.value && form.no.value != form.oldNo.value){
              if(result[0] == 'nameRepeat'){
                  alert("产品名称重复，请重新修改！");
                  return false;
              }else if(result[1] == 'noRepeat'){
                  alert("产品编码重复，请重新修改！");
                  return false;
              }
          }
          if(form.name.value == form.oldName.value && form.no.value != form.oldNo.value){
              if(result[1] == 'noRepeat'){
                  alert("产品编码重复，请重新修改！");
                  return false;
              }
          }
          if(form.name.value != form.oldName.value && form.no.value == form.oldNo.value){
              if(result[0] == 'nameRepeat'){
                  alert("产品名称重复，请重新修改！");
                  return false;
              }
          }
          form.submit();
          
      }
      
  </script>
</head>
<body>
<form id="modForm" action="/sm/controller/product/mod" method="POST">
    <table>
    <input type="hidden" name="id" value="${product.id}"/>
    <input type="hidden" name="typeItemId" value="${product.typeItemId}"/>
    <tr><td>修改产品</td></tr>
        <tr>
            <td>
                                           所属分类：</td>
            <td>
                ${product.typeItem.displayName}
            </td>
            </tr>

            
        <tr>
            <td>
                                         产品编号：</td>
            <td><input type="text" name="no" value="${product.no}" maxlength="100"/><input type="hidden" name="oldNo" value="${product.no}" />
            </td>
        </tr>    
        <tr>
            <td>
                                         名称：</td>
            <td><input type="text" name="name" value="${product.name}" maxlength="100"/><input type="hidden" name="oldName" value="${product.name}" />
            </td>
            </tr>
        <tr>
            <td>
                                          产品当前总量：</td>
            <td><input type="text" name="currentTotalNumber" value="${product.currentTotalNumber}" maxlength="10"/>
            </td>
           
        </tr>    
        <tr>
            <td>
                                          产品总量：</td>
            <td><input type="text" name="totalNumber" value="${product.totalNumber}" maxlength="10"/>
            </td>
           
        </tr>
        <tr><td>&nbsp;</td><td><input type="button" value="提交" onclick="mod();"/></td></tr>
    </table>
</form>
</body>
</html>